﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OLMS.DAL;
using OLMS.BLL;

namespace OLMS.Admin
{
    public partial class GenresView : System.Web.UI.Page
    {
        public int GenreId
        {
            get
            {
                if (Request["gid"] != null)
                {
                    return Convert.ToInt32(Request["gid"]);
                }
                else
                {
                    return 0;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (GenreId != 0)
                {
                    Genres genres = GenreBLL.GetGenresById(GenreId);
                    txtName.Text = genres.Name;
                    txtDesc.Text = genres.Description;
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Genres genres = new Genres();
            genres.GenreId = GenreId;
            genres.Name = txtName.Text;
            genres.Description = txtDesc.Text;
            if (GenreBLL.AddOrEditGenre(genres))
            {
                Response.Redirect("GenresManager.aspx");
            }
            else
            {
                Response.Write("<script>alert('音乐类型保存错误');</script>");
            }
        }

        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("GenresManager.aspx");
        }
    }
}